﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>PerView</title>
    <script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="../../Scripts/ckeditor/ckeditor.js" type="text/javascript"></script>
    <script src="../../Scripts/PageCreater/Scripts/PageCreater.js" type="text/javascript"></script>
    <script type="text/javascript">
        CKEDITOR.on('instanceReady', function (ev) {
            $.get("/TestPaper/GetTestPaperHTMLByID", { id: getUrlPara() }, function (data) {
                InsertHTML(data);
            });
        });

        function InsertHTML(val) {
            var editor = CKEDITOR.instances.editor1;
            var value = val;
            if (editor.mode == 'wysiwyg') {
                editor.insertHtml(value);
            }
            else {
                alert('You must be in WYSIWYG mode!');
            }
        }

        function InsertText(val) {
            var editor = CKEDITOR.instances.editor1;
            var value = val;
            if (editor.mode == 'wysiwyg') {
                editor.insertText(value);
            }
            else {
                alert('You must be in WYSIWYG mode!');
            }
        }

        function SetContents(val) {
            var editor = CKEDITOR.instances.editor1;
            var value = val;
            editor.setData(value);
        }

        function GetContents() {
            var editor = CKEDITOR.instances.editor1;
            return editor.getData();
        }

        function Download() {
            var str = GetContents();
            var arr = str.split("<p>");
            var newArr = new Array();
            var tmp = 0;
            for (var i = 0; i < arr.length; i++) {
                if (arr[i] != "") {
                    var tmpArr = arr[i].split("</p>");
                    newArr[tmp] = tmpArr[0];
                    tmp++;
                }
            }
            var tmpStr = "";
            for (var i = 0; i < newArr.length; i++) {
                tmpStr += newArr[i] + ",";
            }
            var result = tmpStr.substr(0, tmpStr.length - 1);
            $.ajax({
                type: "POST",
                url: "/TestPaper/DownLoadWord",
                data: { str: result },
                success: function () {
                    alert("下载成功！");
                },
                error: function (msg) {
                    debugger;
                    alert(msg);
                }
            }); 
        }
    </script>
</head>
<body>
    <input type="button" value="下载" onclick="Download()" />
    <textarea id="editor1" name="editor1"></textarea>
    <script type="text/javascript">
        CKEDITOR.replace('editor1', {
            on: {
                pluginsLoaded: function (evt) {
                    var doc = CKEDITOR.document, ed = evt.editor;
                    if (!ed.getCommand('bold'))
                        doc.getById('exec-bold').hide();
                    if (!ed.getCommand('link'))
                        doc.getById('exec-link').hide();
                }
            }
        });
    </script>
</body>
</html>
